﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Graphics;

namespace ConjureBivouac2012.Object
{
    public class PlayerDeflecter: AbstractPlayer
    {
        private float shieldStartAngle;

        public PlayerDeflecter(PlayerIndex playerIndex, VehiculeDeflecter vehicule): base(playerIndex)
        {
            this.vehicule = vehicule;
            vehicule.Initialize();
            myName = PLAYER;
            vulnerableTo = ENNEMY + NBULLET;
            //vehicule.LoadContent(GameInfo.GetInstance().GetContent());
        }

        public override void Update(GameTime gameTime)
        {
            GamePadState aGamePad = GamePad.GetState(playerIndex);
            KeyboardState aKeyboard = Keyboard.GetState();

            if (aGamePad.ThumbSticks.Right.Y != 0 && aGamePad.ThumbSticks.Right.X != 0)
            {
                shieldStartAngle = -(float)Math.Atan2(aGamePad.ThumbSticks.Right.Y, aGamePad.ThumbSticks.Right.X);
            }
            else
            {
                int x = 0, y = 0;
                if (aKeyboard.IsKeyDown(Keys.Up))
                    y += 1;
                if (aKeyboard.IsKeyDown(Keys.Down))
                    y -= 1;
                if (aKeyboard.IsKeyDown(Keys.Left))
                    x -= 1;
                if (aKeyboard.IsKeyDown(Keys.Right))
                    x += 1;
                if (x != 0 || y != 0)
                    shieldStartAngle = -(float)Math.Atan2(y, x);
            }

            vehicule.SetRightThumbAngle(shieldStartAngle);
            base.Update(gameTime);
        }

        public void UpdateShield()
        {
            vehicule.GetShield().SetStartingAngle(shieldStartAngle);
        }
    }
}
